﻿using Nop.Core.Plugins;
using Nop.Services.Authentication.External;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using System.Collections.Generic;
using System.Web.Routing;
namespace Nop.Plugin.ExternalJS.Facebook
{
    public class FacebookExternalJSMethod : BasePlugin, IExternalAuthenticationMethod
    {
        #region Fields
        private readonly ISettingService _settingService;
        #endregion
        #region Ctor
        public FacebookExternalJSMethod(ISettingService settingService)
        {
            this._settingService = settingService;
        }
        #endregion
        #region Methods
        /// <summary>
        /// get a route for provider configuration
        /// </summary>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="routeValues"></param>
        public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "Configure";
            controllerName = "ExternalJSFacebook";
            routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.ExternalJS.Facebook.Controllers" }, { "area", null } };
        }
        /// <summary>
        /// get a route for dispaly plugin
        /// </summary>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="routeValues"></param>
        public void GetPublicInfoRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "PublicInfo";
            controllerName = "ExternalJSFacebook";
            routeValues = new RouteValueDictionary { { "Namespaces", "Nop.Plugin.ExternalJS.Facebook.Controllers" }, { "area", null } };
        }

        /// <summary>
        /// Install Plugin
        /// </summary>
        public override void Install()
        {
            var settings = new FacebookExternalJSSettings
            {
                ClientKeyIdentifier = "",
                ClientSecret = "",
            };
            _settingService.SaveSetting(settings);
            //locales
            LocalizationExtensions.AddOrUpdatePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.Login", "Login using Facebook account");
            LocalizationExtensions.AddOrUpdatePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientKeyIdentifier", "App ID/API Key");
            LocalizationExtensions.AddOrUpdatePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientKeyIdentifier.Hint", "Enter your app ID/API key here. You can find it on your FaceBook application page.");
            LocalizationExtensions.AddOrUpdatePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientSecret", "App Secret");
            LocalizationExtensions.AddOrUpdatePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientSecret.Hint", "Enter your app secret here. You can find it on your FaceBook application page.");

            base.Install();
        }

        /// <summary>
        /// Uninstall Plugin
        /// </summary>
        public override void Uninstall(){

            //settings
            _settingService.DeleteSetting<FacebookExternalJSSettings>();

            //locales
            LocalizationExtensions.DeletePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.Login");
            LocalizationExtensions.DeletePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientKeyIdentifier");
            LocalizationExtensions.DeletePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientKeyIdentifier.Hint");
            LocalizationExtensions.DeletePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientSecret");
            LocalizationExtensions.DeletePluginLocaleResource(this,"Plugins.ExternalJS.Facebook.ClientSecret.Hint");

            base.Uninstall();
        }
        #endregion
    }
}
